<fieldset class="tagscloud">
<legend><?php echo $tagLegend ?></legend>
<?php #pr($tags) ?>
	<?php
		$tagx = $tagc = array();
		foreach ($tags as $k => $v) {
			$tagx = explode(', ', $v);
			foreach ($tagx as $xk => $xv) {
				$tagc[] = trim($xv);
			}
		}

		srand((float)microtime() * 1000000);
		shuffle($tagc);
		$tagx = array_count_values($tagc);

		$max_size = 15; $max_weight = 400;
		$min_size = 10; $min_weight = 150;
		$max_qty = max(array_values($tagx));
		$min_qty = min(array_values($tagx));

		$spread = $max_qty - $min_qty;
		if (0 == $spread) {
			$spread = 1;
		}

		$step = ($max_size - $min_size)/($spread);
		$bold = ($max_weight - $min_weight)/($spread);
		$cloud = '';
		foreach($tagx as $name => $value) {
			$size = round($min_size + (($value - $min_qty) * $step),0);
			$weight = round($min_weight + (($value - $min_qty) * $bold),0);
			$cloud .= '<a href="/'. $tagLink .'/'. $name .'/" style="font-weight:'.$weight.'; font-size:'.$size.'pt">'. $name .'</a> ';
		}

		echo $cloud;
	?>
</fieldset>
